package com.tronsis.recyclerviewdemo.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.tronsis.recyclerviewdemo.R;

import java.util.List;

/**
 * @author scofield@tronsis.com
 * @date 2016/11/7 17:12
 */

public class HorizontalRVAdapter extends RecyclerView.Adapter<HorizontalRVAdapter.ViewHolderHorizontal> {
    public static final int DEFAULE = 0;
    public static final int CARD = 1;

    private List<String> mData;
    private int mode;

    public HorizontalRVAdapter(List<String> data,int mode) {
        this.mData = data;
    }


    @Override
    public ViewHolderHorizontal onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        switch (mode) {
            case CARD:
                 view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_horizontal_card, null);
                break;

            case DEFAULE:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_horizontal, null);
                default:
                    break;
        }

        ViewHolderHorizontal viewHolderHorizontal = new ViewHolderHorizontal(view);
        return viewHolderHorizontal;
    }

    @Override
    public void onBindViewHolder(ViewHolderHorizontal holder, int position) {
        holder.tv.setText(mData.get(position));
    }


    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }

    class ViewHolderHorizontal extends RecyclerView.ViewHolder {
        TextView tv;

        public ViewHolderHorizontal(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.tv);
        }
    }

}
